package cn.sjtu.design_pattern.singleton;

/**
 * @author syo 2319615164@qq.com
 * @description 双重检查锁单例
 * @date 2024/5/16
 * @Copyright syo
 */
public class Singleton02 {
    // 1. 私有化构造函数
    private Singleton02() {}

    // 2. 成员变量
    private static volatile Singleton02 INSTANCE = null;

    // 3. 获取单例的方法
    public static Singleton02 getInstance() {
        if (INSTANCE == null) {
            synchronized (Singleton02.class) {
                if (INSTANCE == null) {
                    INSTANCE = new Singleton02();
                }
            }
        }
        return INSTANCE;
    }
}
